package 笔试.科大讯飞;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * @author:谢君臣
 * @Date:2021/10/10-20:40
 * @version:1.0
 * @function:
 */
public class Main03 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int [] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = scanner.nextInt();
        }
        int res = longeset(x);
        System.out.println(res);
    }

    private static int longeset(int[] x) {
        ArrayList<Unit> list = new ArrayList<>();
        int length = x.length;
        if (length<=1)
            return length;
        int last = x[0];
        int varl = last,le = 1,index =0;
        for (int i = 1; i < length; i++) {
            if (x[i]==last) {
                le++;
            }else {
                Unit unit = new Unit(varl,le,index);
                list.add(unit);
                varl = x[i];
                le =1;
                index =i;
            }
            last = x[i];
        }
        int maxlen = 0;
        for (Unit un : list) {
            if (un.length>maxlen) {
                maxlen = un.length;
            }
        }
        int re =0;
        for (Unit u : list) {
            int max = maxlen;
            if (u.length==maxlen) {
                int i = u.index;
                if (i>2&&x[i-2]==u.var) {
                    max++;
                }
//                i+u.length+1<&&x[]

            }
        }
        return 0;
    }
    static class Unit{
        int var;
        int length;
        int index;

        public Unit(int var, int length, int index) {
            this.var = var;
            this.length = length;
            this.index = index;
        }
    }
}
